package view;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.inject.Inject;

import controller.EmployeeController;
import entity.Employee;
import entity.Salaried;

@ManagedBean(name="login")
@SessionScoped
public class Login {
	@Inject
	EmployeeController controller;
	private String Username;
	private String Password;
	private boolean loggedIn = false;
	private Employee employee;

	public String LoginSystem() {
		
		if (Username.equals("admin") && Password.equals("admin")) {
			loggedIn=true;
			return "admin";
		} else {
			Employee employee = controller
					.CredentialControl(Username, Password);
			if (employee == null) {
				return "Fail";
			} else {
				this.employee = employee;
				loggedIn = true;
				return employee.getClass().getSimpleName();

			}
		}
		}

	public String Logout() {
		this.employee = null;
		loggedIn = false;
		return "Logout";
	}

	public String getUsername() {
		return Username;
	}

	public void setUsername(String username) {
		Username = username;
	}

	public String getPassword() {
		return Password;
	}

	public void setPassword(String password) {
		Password = password;
	}

	public boolean isLoggedIn() {
		return loggedIn;
	}

	public void setLoggedIn(boolean loggedIn) {
		this.loggedIn = loggedIn;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

}
